import javax.swing.*;

public class TimeThread {
    public static int time = 0;
    static final int T = 1000;//定义计时器的间隔时间1000毫秒
    Timer timer;


    public TimeThread() {
        timer = new Timer(T, e -> {
            String prefix = "";
            if (time < 9) {
                //System.out.println("hai" + time++);
                prefix = "00";
            } else if (time < 99) {
                prefix = "0";
            } /*else if (time < 1000) {

            }*/

            //更新JLabel显示
            String finalPrefix = prefix;
            new Thread(new Runnable() {
                @Override
                public void run() {
                    //System.out.println(prefix+"  " +time);
                    TimePanel.timeText.setText(finalPrefix + time);
                }
            }).start();

            time++;
        });
    }

    public void start() {
        timer.start();
    }

    public void stop() {
        timer.stop();
    }

}
